package cn.edu.zju.gis.disasterBE.sever.dao;

import cn.edu.zju.gis.disasterBE.sever.entity.DisasterResponse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.List;

public interface DisasterResponseDAO extends BaseMapper<DisasterResponse> {

    @Select("select * from disaster_response order by end_time desc")
    List<DisasterResponse> disasterGetAll();

    @Select("select * from disaster_response where end_time is null order by start_time asc")
    List<DisasterResponse> durableDisasterGet();

    default boolean saveDisaster(DisasterResponse disasterResponse)
    {
        return this.insert(disasterResponse) > 0;
    }

    @Update("update disaster_response set end_time = #{endTime} where did = #{did}")
    int endResponse(Integer did, Timestamp endTime);

    @Select("select did from disaster_response where name = #{name}")
    int getDid(String name);
}
